package com.heima.wemedia.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {

    public static final String DEAD_EXCHANGE_NAME = "dead_exchange";
    public static final String SEND_QUEUE_NAME = "send";
    public static final String DEAD_QUEUE_NAME = "dead_queue";
    public static final String DEAD_LETTER_ROUTINGKEY = "dead";
    @Bean
    public Queue sendQueue(){
        //创建发送消息队列
        return QueueBuilder.durable(SEND_QUEUE_NAME)
                .deadLetterExchange(DEAD_EXCHANGE_NAME)
                .deadLetterRoutingKey(DEAD_LETTER_ROUTINGKEY).build();
    }

    @Bean
    public Queue deadQueue(){
        //创建死信队列
        return QueueBuilder.durable(DEAD_QUEUE_NAME).build();
    }
    @Bean
    public Exchange deExchange(){
        //创建死信交换机
        return ExchangeBuilder.directExchange(DEAD_EXCHANGE_NAME).durable(true).build();
    }

    @Bean
    public Binding queue2Exchange() {
        //绑定死信交换机和死信队列
        return BindingBuilder.bind(sendQueue()).to(deExchange()).with(DEAD_LETTER_ROUTINGKEY).noargs();
    }
}
